<?php
    $libraryid = $_POST['libraryid'];
    $location = $_POST['location'];
    $password1 = $_POST['password1'];
    $password2 = $_POST['password2'];
    $stat = 1;
    //echo $location;
    //echo $libraryid;
    require('db_connection.php');
    //$query="UPDATE tblclient SET cpassword=password('$password1'), stat='$stat' WHERE librarycardNo like '$libraryid' AND location LIKE '$location'";
    if($libraryid=="" || $location=="" || $password1=="" || $password2=="")
    {
        echo"<script> alert('Please fill all the fields.');</script>";
        echo("<script> document.location.href='activate.php'</script>");
    }
    else{
      if( $password1 != $password2)
      {
        echo"<script> alert('Your password did not match!');</script>";
        echo("<script> document.location.href='activate.php'</script>");
      }
      else{
        $query1 = "SELECT * FROM tblclient WHERE libraryCardNo='$libraryid' AND libraryNo = '$location'";
        $result1 = mysql_query($query1);
        $clientcount = mysql_num_rows($result1);
        if($clientcount > 0)
        {
           $query="UPDATE tblclient SET cpassword=PASSWORD('$password1'), stat='1' WHERE libraryCardNo like '$libraryid' AND libraryNo LIKE '$location'";
            $result = mysql_query($query);
            if($result)
            {
                echo"<script> alert('Your account has been activated.');</script>";
                echo("<script> document.location.href='index.php'</script>");

            }
            else
            {
              echo"<script> alert('Activation failed.');</script>";
              echo("<script> history.back();</script>");
            }

        }
        else{
          echo"<script> alert('Please check your library card number and the library where you registered.');</script>";
          echo("<script> document.location.href='activate.php'</script>");
        }
       

      }
        
    }
    
   
?>
